import 'package:flutter/material.dart';
import 'package:flutter_dk_form/flutter_dk_form.dart';

class FloatingMenuDemoPage extends StatelessWidget {
  static const String routeName = '/page/floating_menu_demo_page';
  static const String name = "FloatingMenu Demo";
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'FloatingMenu Demo',
      home: FloatingMenuDemoPageState(),
    );
  }
}

class FloatingMenuDemoPageState extends StatefulWidget {

  @override
  _FloatingMenuDemoPageStateState createState() => _FloatingMenuDemoPageStateState();
}

class _FloatingMenuDemoPageStateState extends State<FloatingMenuDemoPageState>
    implements FloatingMenuCallback {
  String centerText = "拨打电话";

  @override
  Widget build(BuildContext context) {
    final List<FloatingMenuItem> floatMenuList = [
      FloatingMenuItem(
          id: 1,
          icon: Image(image: NetworkImage("http://172.18.130.18/favicon.ico")),
          backgroundColor: Color(0xFFEEEEEE),
          title: "拨打电话"),
      FloatingMenuItem(
          id: 2,
          icon: Image(image: NetworkImage("http://172.18.130.18/favicon.ico")),
          backgroundColor: Color(0xFFEEEEEE),
          title: "约看"),
      FloatingMenuItem(
          id: 3,
          icon: Image(image: NetworkImage("http://172.18.130.18/favicon.ico")),
          backgroundColor: Color(0xFFEEEEEE),
          title: "约看反馈"),
      FloatingMenuItem(
          id: 4,
          icon: Image(image: NetworkImage("http://172.18.130.18/favicon.ico")),
          backgroundColor: Color(0xFFEEEEEE),
          title: "无效"),
      FloatingMenuItem(
          id: 5,
          icon: Image(image: NetworkImage("http://172.18.130.18/favicon.ico")),
          backgroundColor: Color(0xFFEEEEEE),
          title: "快速评测"),
      FloatingMenuItem(
          id: 6, backgroundColor: Color(0xFFEEEEEE), title: "快速评测无图标"),
    ];

    return Scaffold(
      resizeToAvoidBottomPadding: true,
      appBar: AppBar(
        title: Text('FloatingMenu Demo'),
      ),
      body: Stack(
        children: <Widget>[
          InkWell(
            onTap: () {
              print("============================");
            },
            child: Container(
              child: Center(
                child: Text(
                  centerText,
                  style: TextStyle(color: Colors.black),
                ),
              ),
            ),
          ),
          FloatingMenu(
            menuList: floatMenuList,
            callback: this,
            btnBackgroundColor: Color(0xFF3DBCC6),
            preMenuIcon: Icon(Icons.add),
            postMenuIcon: Icon(Icons.clear),
            btnText: '操作台',
            hasAnimation: false,
          ),
        ],
      ),
    );
  }

  @override
  void onMenuClick(FloatingMenuItem floatingMenuItem) {
    print("onMenuClicked : " + floatingMenuItem.id.toString());
    switch (floatingMenuItem.id) {
      case 1:
        {
          centerText = "拨打电话";
        }
        break;
      case 2:
        {
          centerText = "约看";
        }
        break;
      case 3:
        {
          centerText = "约看反馈";
        }
        break;
      case 4:
        {
          centerText = "无效";
        }
        break;
      case 5:
        {
          centerText = "快速评测";
        }
        break;
      case 6:
        {
          centerText = "快速评测无图标";
        }
        break;
    }

    setState(() {});
  }
}
